<?php
/**
 * @file $HeadURL: commenttype.php $
 * @author $Author: LL $
 * @date $Date: 2015-7-10 $
 */
namespace haibao\comment\data;

class CommentType extends \haibao\comment\data\BaseMysql{
    public function __construct(){
        parent::__construct( '\haibao\comment\model\data\commenttype' );
    }  
    public function getByName($commentTypeName, $commentTypeId = null){
        $model = null;
        $sql = "select * from `CommentType` where TypeName=%s and TypeStatus=%s";
        $valArr = array(
            $commentTypeName,
            \haibao\comment\model\data\CommentType::STATUS_OK
        );
        
        if($commentTypeId){
            $sql .= " and Id <>%s";
            array_push($valArr, $commentTypeId);
        }
        
        $result = $this->query($sql, $valArr);
        while ($result->fetch_assoc()){
            $model = new \haibao\comment\model\data\CommentType();
            foreach($model->getKeyMap() as $keyName=>$keyType){
                $model->$keyName = $result->getData($keyType->getFieldName());
            }
        }
        return $model;
    }
    
    public function getByCode($commentTypeCode, $commentTypeId = null){
        $model = null;
        $sql = "select * from `CommentType` where TypeCode=%s and TypeStatus=%s";
        $valArr = array(
            $commentTypeCode,
            \haibao\comment\model\data\CommentType::STATUS_OK
        );
        
        if($commentTypeId){
            $sql .= " and Id <>%s";
            array_push($valArr, $commentTypeId);
        }
        
        $result = $this->query($sql, $valArr);
        while ($result->fetch_assoc()){
            $model = new \haibao\comment\model\data\CommentType();
            foreach($model->getKeyMap() as $keyName=>$keyType){
                $model->$keyName = $result->getData($keyType->getFieldName());
            }
        }
        return $model;
    }
}